﻿var ReportAutoComElem = null;
var ReportAutoComElemVal = null;
var ReportTimerId = null;
$(document).ready(function () {
    var path = window.location.pathname;
    if ((path.indexOf("FrmCustomerInvoiceReport") != -1)
        || (path.indexOf("FrmCountryCustomerGroupRevenueReport") != -1)
        || (path.indexOf("FrmCustomerPaymentReport") != -1)
        || (path.indexOf("FrmCustomerGroupReport") != -1)
        || (path.indexOf("FrmVendorGroupReport") != -1)
        || (path.indexOf("FrmGuideGroupReport") != -1)
        || (path.indexOf("FrmGroupGuideReport") != -1)
        || (path.indexOf("FrmCountryCustomerGroupBalanceReport") != -1)
        || (path.indexOf("FrmGroupRegionRoomDayReport") != -1)
        || (path.indexOf("FrmGroupCityRoomDayReport") != -1)
        || (path.indexOf("FrmCustomerARDaysReport") != -1)
        || (path.indexOf("FrmCustomerPaymentTypeReport") != -1)
        || (path.indexOf("FrmCustomerRefundReport") != -1)
        || (path.indexOf("FrmGuideListReport") != -1)
        || (path.indexOf("FrmHotelContractsReport") != -1)
        || (path.indexOf("FrmGroupBreakDownReport") != -1)) {
        InitSearchDeteilsDataCalendar();
        $.validator.addMethod("ReportRequired", $.validator.methods.required, Messages["ReportRequireds"]);
        $.validator.addMethod("ReportDate", $.validator.methods.datePicker, Messages["ReportDates"]);
        $.validator.addClassRules({
            Required: {
                ReportRequired: true,
            },
            Date: {
                ReportDate: true,
            },
        });

        $('#CustomerInvoiceSummaryReportForm').validate();
        $('#CountryCustomerGroupRevenueReportForm').validate();
        $('#CustomerPaymentReportForm').validate();
        $('#CustomerGroupReportForm').validate();
        $('#VendorGroupReportForm').validate();
        $('#GuideGroupReportForm').validate();
        $('#GroupGuideReportForm').validate();
        $('#CountryCustomerGroupBalanceReportForm').validate();
        $('#GroupRegionRoomDayReportForm').validate();
        $('#GroupCityRoomDayReportForm').validate();
        $('#CustomerARDaysReportForm').validate();
        $('#CustomerPaymentTypeReportForm').validate();
        $('#CustomerRefundReportForm').validate();
        $('#GuideListReportForm').validate();
        $('#HotelContractsReportForm').validate();
        $('#GroupBreakDownReportForm').validate();
    }

});
$(document).on('change', '.TextBox', function () {
    $(this).valid();
});
$(document).on('click', '#CancelButton', function () {
    window.location = '/';
});
$(document).on('change', '.DropDown', function () {
    $(this).valid();
});
function InitSearchDeteilsDataCalendar() {
    $(".SearchDeteilsDataCalendarFrom").datepicker({
        defaultDate: "+1w",
        changeMonth: true,
        changeYear: true,
        numberOfMonths: 1,
        dateFormat: 'dd/M/yy',
        beforeShow: function (input) {
            $(input).css({
                "position": "relative",
                "z-index": 5
            });
        },
        onClose: function (selectedDate) {
            $(".SearchDeteilsDataCalendarTo").datepicker("option", "minDate", selectedDate);
        }
    });
    $(".SearchDeteilsDataCalendarTo").datepicker({
        defaultDate: "+1w",
        changeMonth: true,
        changeYear: true,
        numberOfMonths: 1,
        dateFormat: 'dd/M/yy',
        beforeShow: function (input) {
            $(input).css({
                "position": "relative",
                "z-index": 5
            });
        },
        onClose: function (selectedDate) {
            $(".SearchDeteilsDataCalendarFrom").datepicker("option", "maxDate", selectedDate);
        }
    });
}
$(document).on('click', '#CustomerInvoiceSumBtn', function () {
    if ($('#CustomerInvoiceSummaryReportForm').valid())
        if ($("#SelectedCustomerID").val() != null && $("#SelectedCustomerID").val() != "" && parseInt($("#SelectedCustomerID").val()) > 0) {
            $("#LoadingDiv").show();
            var FrmCustomerInvoiceSummaryReportViewModel = {
                SelectedCustomerID: $("#SelectedCustomerID").val(),
                RunExcel: $("#RunExcel").is(":checked"),
                BeginningDate: $("#BeginningDate").val(),
                EndingDate: $("#EndingDate").val(),
            };

            var DTO = JSON.stringify(FrmCustomerInvoiceSummaryReportViewModel);
            $.ajax({
                url: urls["ReportCustomerInvoiceSummaryReport"],
                type: 'POST',
                contentType: 'application/json; charset=utf-8',
                data: DTO,
                success: function (data) {
                    if (data.success) {
                        window.open(urls["ReportCustomerInvoiceSummaryReportOpen"]);
                    }
                },
                error: function (xhr) {
                    jAlert(xhr.statusText, "Error");
                },
                complete: function () {
                    $("#LoadingDiv").hide();
                }
            });
        }
        else
            jAlert("Choose customer from autocomplete div:", "Error!");
});
$(document).on('click', '#CountryCustomerGroupRevenueSumBtn', function () {
    if ($('#CountryCustomerGroupRevenueReportForm').valid())
    {
        $("#LoadingDiv").show();
        var FrmCountryCustomerGroupRevenueReportViewModel = {
            SelectedNationalityID: $("#SelectedNationalityID").val(),
            BeginningDate: $("#BeginningDate").val(),
            EndingDate: $("#EndingDate").val(),
            RunExcel: $("#RunExcel").is(":checked"),
        };

        var DTO = JSON.stringify(FrmCountryCustomerGroupRevenueReportViewModel);
        $.ajax({
            url: urls["ReportCountryCustomerGroupRevenueReport"],
            type: 'POST',
            contentType: 'application/json; charset=utf-8',
            data: DTO,
            success: function (data) {
                if (data.success) {
                    window.open(urls["ReportCountryCustomerGroupRevenueReportOpen"]);
                }
            },
            error: function (xhr) {
                jAlert(xhr.statusText, "Error");
            },
            complete: function () {
                $("#LoadingDiv").hide();
            }
        });
    }
});
$(document).on('click', '#CustomerPaymentSumBtn', function () {
    if ($('#CustomerPaymentReportForm').valid())
        if ($("#SelectedCustomerID").val() != null && $("#SelectedCustomerID").val() != "" && parseInt($("#SelectedCustomerID").val()) > 0) {
            $("#LoadingDiv").show();
            var FrmCustomerPaymentReportViewModel = {
                SelectedCustomerID: $("#SelectedCustomerID").val(),
                RunExcel: $("#RunExcel").is(":checked"),
                BeginningDate: $("#BeginningDate").val(),
                EndingDate: $("#EndingDate").val(),
            };

            var DTO = JSON.stringify(FrmCustomerPaymentReportViewModel);
            $.ajax({
                url: urls["ReportCustomerPaymentReport"],
                type: 'POST',
                contentType: 'application/json; charset=utf-8',
                data: DTO,
                success: function (data) {
                    if (data.success) {
                        window.open(urls["ReportCustomerPaymentReportOpen"]);
                    }
                },
                error: function (xhr) {
                    jAlert(xhr.statusText, "Error");
                },
                complete: function () {
                    $("#LoadingDiv").hide();
                }
            });
        }
        else
            jAlert("Choose customer from autocomplete div:", "Error!");
});
$(document).on('click', '#CustomerGroupSumBtn', function () {
    if ($('#CustomerGroupReportForm').valid())
        if ($("#SelectedCustomerID").val() != null && $("#SelectedCustomerID").val() != "" && parseInt($("#SelectedCustomerID").val()) > 0) {
            $("#LoadingDiv").show();
            var FrmCustomerGroupReportViewModel = {
                SelectedCustomerID: $("#SelectedCustomerID").val(),
                SelectedIsGir: $("#SelectedIsGir").val(),
                RunExcel: $("#RunExcel").is(":checked"),
                BeginningDate: $("#BeginningDate").val(),
                EndingDate: $("#EndingDate").val(),
            };

            var DTO = JSON.stringify(FrmCustomerGroupReportViewModel);
            $.ajax({
                url: urls["ReportCustomerGroupReport"],
                type: 'POST',
                contentType: 'application/json; charset=utf-8',
                data: DTO,
                success: function (data) {
                    if (data.success) {
                        window.open(urls["ReportCustomerGroupReportOpen"]);
                    }
                },
                error: function (xhr) {
                    jAlert(xhr.statusText, "Error");
                },
                complete: function () {
                    $("#LoadingDiv").hide();
                }
            });
        }
        else
            jAlert("Choose customer from autocomplete div:", "Error!");
});
$(document).on('click', '#VendorGroupSumBtn', function () {
    if ($('#VendorGroupReportForm').valid())
        if ($("#SelectedVendorID").val() != null && $("#SelectedVendorID").val() != "" && parseInt($("#SelectedVendorID").val()) > 0) {
            var SelectedTabColumns = [];
            $('#TabColumns input[name=SelectedTabColumns]:checked').each(function () {
                SelectedTabColumns.push($(this).val());
            });
            var SelectedStatus = [];
            $('#Statuses input[name=SelectedStatus]:checked').each(function () {
                SelectedStatus.push($(this).val());
            });
            if (SelectedTabColumns.length > 0) {
                if (SelectedStatus.length > 0) {
                    $("#LoadingDiv").show();
                    var FrmVendorGroupReportViewModel = {
                        SelectedTab: $("#SelectedTab").val(),
                        PaperType: $("#PaperType").val(),
                        SelectedVendorID: $("#SelectedVendorID").val(),
                        SelectedIsGir: $("#SelectedIsGir").val(),
                        RunExcel: $("#RunExcel").is(":checked"),
                        Lower: $("#Lower").val(),
                        Upper: $("#Upper").val(),
                        ReportCitySearch: $("#ReportCitySearch").val(),
                        SelectedCategory: $("#SelectedCategory").val(),
                        SelectedPlane: $("#SelectedPlane").val(),
                        SelectedCityText: $("#SelectedCityText option:selected").text() != "select" ? $("#SelectedCityText option:selected").text() : null,
                        SelectedTabColumns: SelectedTabColumns.length > 0 ? SelectedTabColumns : [],
                        SelectedStatus: SelectedStatus.length > 0 ? SelectedStatus : [],
                    };

                    var DTO = JSON.stringify(FrmVendorGroupReportViewModel);
                    $.ajax({
                        url: urls["ReportVendorGroupReport"],
                        type: 'POST',
                        contentType: 'application/json; charset=utf-8',
                        data: DTO,
                        success: function (data) {
                            if (data.success) {
                                window.open(urls["ReportVendorGroupReportOpen"]);
                            }
                        },
                        error: function (xhr) {
                            jAlert(xhr.statusText, "Error");
                        },
                        complete: function () {
                            $("#LoadingDiv").hide();
                        }
                    });
                }
                else
                    jAlert("Should be selected at Statuses list one:", "Error!");
            }
            else
                jAlert("Should be selected at Columns list one:", "Error!");
        }
        else
            jAlert("Choose vendor name from autocomplete div:", "Error!");
});
$(document).on('click', '#GuideGroupSumBtn', function () {
    if ($('#GuideGroupReportForm').valid())
        if ($("#SelectedGuideID").val() != null && $("#SelectedGuideID").val() != "" && parseInt($("#SelectedGuideID").val()) > 0) {
            $("#LoadingDiv").show();
            var FrmGuideGroupReportViewModel = {
                SelectedGuideID: $("#SelectedGuideID").val(),
                SelectedIsGir: $("#SelectedIsGir").val(),
                RunExcel: $("#RunExcel").is(":checked"),
                Lower: $("#Lower").val(),
                Upper: $("#Upper").val(),
            };

            var DTO = JSON.stringify(FrmGuideGroupReportViewModel);
            $.ajax({
                url: urls["ReportGuideGroupReport"],
                type: 'POST',
                contentType: 'application/json; charset=utf-8',
                data: DTO,
                success: function (data) {
                    if (data.success) {
                        window.open(urls["ReportGuideGroupReportOpen"]);
                    }
                },
                error: function (xhr) {
                    jAlert(xhr.statusText, "Error");
                },
                complete: function () {
                    $("#LoadingDiv").hide();
                }
            });
        }
        else
            jAlert("Choose guide from autocomplete div:", "Error!");
});
$(document).on('click', '#GroupGuideSumBtn', function () {
    if ($('#GroupGuideReportForm').valid())
    {
        $("#LoadingDiv").show();
        var FrmGroupGuideReportViewModel = {
            Lower: $("#Lower").val(),
            Upper: $("#Upper").val(),
            RunExcel: $("#RunExcel").is(":checked"),
            SelectedIsGir: $("#SelectedIsGir").val(),
        };

        var DTO = JSON.stringify(FrmGroupGuideReportViewModel);
        $.ajax({
            url: urls["ReportGroupGuideReport"],
            type: 'POST',
            contentType: 'application/json; charset=utf-8',
            data: DTO,
            success: function (data) {
                if (data.success) {
                    window.open(urls["ReportGroupGuideReportOpen"]);
                }
            },
            error: function (xhr) {
                jAlert(xhr.statusText, "Error");
            },
            complete: function () {
                $("#LoadingDiv").hide();
            }
        });
    }
});
$(document).on('click', '#CountryCustomerGroupBalanceSumBtn', function () {
    if ($('#CountryCustomerGroupBalanceReportForm').valid())
    {
        $("#LoadingDiv").show();
        var FrmCountryCustomerGroupBalanceReportViewModel = {
            SelectedNationalityID: $("#SelectedNationalityID").val(),
            BeginningDate: $("#BeginningDate").val(),
            EndingDate: $("#EndingDate").val(),
            RunExcel: $("#RunExcel").is(":checked"),
        };

        var DTO = JSON.stringify(FrmCountryCustomerGroupBalanceReportViewModel);
        $.ajax({
            url: urls["ReportCountryCustomerGroupBalanceReport"],
            type: 'POST',
            contentType: 'application/json; charset=utf-8',
            data: DTO,
            success: function (data) {
                if (data.success) {
                    window.open(urls["ReportCountryCustomerGroupBalanceReportOpen"]);
                }
            },
            error: function (xhr) {
                jAlert(xhr.statusText, "Error");
            },
            complete: function () {
                $("#LoadingDiv").hide();
            }
        });
    }
});
$(document).on('click', '#GroupRegionRoomDayBtn', function () {
    if ($('#GroupRegionRoomDayReportForm').valid())
    {
        $("#LoadingDiv").show();
        var FrmGroupRegionRoomDayReportViewModel = {
            BeginningDate: $("#BeginningDate").val(),
            EndingDate: $("#EndingDate").val(),
            RunExcel: $("#RunExcel").is(":checked"),
        };

        var DTO = JSON.stringify(FrmGroupRegionRoomDayReportViewModel);
        $.ajax({
            url: urls["ReportGroupRegionRoomDayReport"],
            type: 'POST',
            contentType: 'application/json; charset=utf-8',
            data: DTO,
            success: function (data) {
                if (data.success) {
                    window.open(urls["ReportGroupRegionRoomDayReportOpen"]);
                }
            },
            error: function (xhr) {
                jAlert(xhr.statusText, "Error");
            },
            complete: function () {
                $("#LoadingDiv").hide();
            }
        });
    }
});
$(document).on('click', '#GroupCityRoomDayBtn', function () {
    if ($('#GroupCityRoomDayReportForm').valid())
    {
        $("#LoadingDiv").show();
        var FrmGroupCityRoomDayReportViewModel = {
            BeginningDate: $("#BeginningDate").val(),
            EndingDate: $("#EndingDate").val(),
            RunExcel: $("#RunExcel").is(":checked"),
        };

        var DTO = JSON.stringify(FrmGroupCityRoomDayReportViewModel);
        $.ajax({
            url: urls["ReportGroupCityRoomDayReport"],
            type: 'POST',
            contentType: 'application/json; charset=utf-8',
            data: DTO,
            success: function (data) {
                if (data.success) {
                    window.open(urls["ReportGroupCityRoomDayReportOpen"]);
                }
            },
            error: function (xhr) {
                jAlert(xhr.statusText, "Error");
            },
            complete: function () {
                $("#LoadingDiv").hide();
            }
        });
    }
});
$(document).on('click', '#CustomerARDayesSumBtn', function () {
    if ($('#CustomerARDaysReportForm').valid())
        if ($("#SelectedCustomerID").val() != null && $("#SelectedCustomerID").val() != "" && parseInt($("#SelectedCustomerID").val()) > 0) {
            $("#LoadingDiv").show();
            var FrmCustomerARDaysReportViewModel = {
                SelectedCustomerID: $("#SelectedCustomerID").val(),
                RunExcel: $("#RunExcel").is(":checked"),
                BeginningDate: $("#BeginningDate").val(),
                EndingDate: $("#EndingDate").val(),
            };

            var DTO = JSON.stringify(FrmCustomerARDaysReportViewModel);
            $.ajax({
                url: urls["ReportCustomerARDaysReport"],
                type: 'POST',
                contentType: 'application/json; charset=utf-8',
                data: DTO,
                success: function (data) {
                    if (data.success) {
                        window.open(urls["ReportCustomerARDaysReportOpen"]);
                    }
                },
                error: function (xhr) {
                    jAlert(xhr.statusText, "Error");
                },
                complete: function () {
                    $("#LoadingDiv").hide();
                }
            });
        }
        else
            jAlert("Choose customer from autocomplete div:", "Error!");
});
$(document).on('click', '#CustomerPaymentTypeSumBtn', function () {
    if ($('#CustomerPaymentTypeReportForm').valid())
    {
        $("#LoadingDiv").show();
        var FrmCustomerPaymentTypeReportViewModel = {
            SelectedPaymentTypeID: $("#SelectedPaymentTypeID").val(),
            RunExcel: $("#RunExcel").is(":checked"),
            BeginningDate: $("#BeginningDate").val(),
            EndingDate: $("#EndingDate").val(),
        };

        var DTO = JSON.stringify(FrmCustomerPaymentTypeReportViewModel);
        $.ajax({
            url: urls["ReportCustomerPaymentTypeReport"],
            type: 'POST',
            contentType: 'application/json; charset=utf-8',
            data: DTO,
            success: function (data) {
                if (data.success) {
                    window.open(urls["ReportCustomerPaymentTypeReportOpen"]);
                }
            },
            error: function (xhr) {
                jAlert(xhr.statusText, "Error");
            },
            complete: function () {
                $("#LoadingDiv").hide();
            }
        });
    }
});
$(document).on('click', '#CustomerRefundSumBtn', function () {
    if ($('#CustomerRefundReportForm').valid())
        if ($("#SelectedCustomerID").val() != null && $("#SelectedCustomerID").val() != "" && parseInt($("#SelectedCustomerID").val()) > 0) {
            $("#LoadingDiv").show();
            var FrmCustomerRefundReportViewModel = {
                SelectedCustomerID: $("#SelectedCustomerID").val(),
                BeginningDate: $("#BeginningDate").val(),
                EndingDate: $("#EndingDate").val(),
                RunExcel: $("#RunExcel").is(":checked"),
            };

            var DTO = JSON.stringify(FrmCustomerRefundReportViewModel);
            $.ajax({
                url: urls["ReportCustomerRefundReport"],
                type: 'POST',
                contentType: 'application/json; charset=utf-8',
                data: DTO,
                success: function (data) {
                    if (data.success) {
                        window.open(urls["ReportCustomerRefundReportOpen"]);
                    }
                },
                error: function (xhr) {
                    jAlert(xhr.statusText, "Error");
                },
                complete: function () {
                    $("#LoadingDiv").hide();
                }
            });
        }
        else
            jAlert("Choose customer from autocomplete div:", "Error!");
});
$(document).on('click', '#GuideListSumBtn', function () {
    if ($('#GuideListReportForm').valid())
    {
        $("#LoadingDiv").show();
        var FrmGuideListReportViewModel = {
            SelectedRegionID: $("#SelectedRegionID").val(),
            RunExcel: $("#RunExcel").is(":checked"),
        };

        var DTO = JSON.stringify(FrmGuideListReportViewModel);
        $.ajax({
            url: urls["ReportGuideListReport"],
            type: 'POST',
            contentType: 'application/json; charset=utf-8',
            data: DTO,
            success: function (data) {
                if (data.success) {
                    window.open(urls["ReportGuideListReportOpen"]);
                }
            },
            error: function (xhr) {
                jAlert(xhr.statusText, "Error");
            },
            complete: function () {
                $("#LoadingDiv").hide();
            }
        });
    }
});
$(document).on('click', '#GroupBreakDownSumBtn', function () {
    if ($('#GroupBreakDownReportForm').valid()) {
        $("#LoadingDiv").show();
        var FrmGroupBreakDownReportViewModel = {
            SelectedIsGir: $("#SelectedIsGir").val(),
            RunExcel: $("#RunExcel").is(":checked"),
            BeginningDate: $("#BeginningDate").val(),
            EndingDate: $("#EndingDate").val(),
        };

        var DTO = JSON.stringify(FrmGroupBreakDownReportViewModel);
        $.ajax({
            url: urls["ReportGroupBreakDownReport"],
            type: 'POST',
            contentType: 'application/json; charset=utf-8',
            data: DTO,
            success: function (data) {
                if (data.success) {
                    window.open(urls["ReportGroupBreakDownReportOpen"]);
                }
            },
            error: function (xhr) {
                jAlert(xhr.statusText, "Error");
            },
            complete: function () {
                $("#LoadingDiv").hide();
            }
        });
    }
});
$(document).on('click', '#HotelContractsSumBtn', function () {
    if ($('#HotelContractsReportForm').valid())
        window.open("../Report/HotelContractsReport?RegionID=" + $("#SelectedRegionID").val()
            + "&SeasonID=" + $("#SelectedSeasonID").val(), '_blank');
});

$(document).on('click', '.VendorGroupAllStatusSpan', function () {
    $('#VendorGroupAllStatus').prop('checked', !($('#VendorGroupAllStatus').is(':checked')));
    var VendorGroupAllStatus = $('#Statuses input[name=SelectedStatus]');
    var IsChecked = $('#VendorGroupAllStatus').prop("checked");
    $(VendorGroupAllStatus).each(function (index, elem) {
        $(elem).prop('checked', IsChecked)
    });
});
$(document).on('change', '#VendorGroupAllStatus', function () {
    var VendorGroupAllStatus = $('#Statuses input[name=SelectedStatus]');
    var IsChecked = $('#VendorGroupAllStatus').prop("checked");
    $(VendorGroupAllStatus).each(function (index, elem) {
        $(elem).prop('checked', IsChecked)
    });
});
$(document).on('change', '.VendorGroupStatusChechBoxChange', function () {
    var CheckBoxStates = $('#Statuses input[name=SelectedStatus]');
    var IsChecked = true;
    $(CheckBoxStates).each(function (index, elem) {
        if (!$(elem).prop('checked')) {
            IsChecked = false;
            return
        }
    });
    $('#VendorGroupAllStatus').prop('checked', IsChecked);
});
$(document).on('click', '.VendorGroupAllColumnSpan', function () {
    $('#VendorGroupAllColumn').prop('checked', !($('#VendorGroupAllColumn').is(':checked')));
    var VendorGroupAllColumn = $('#TabColumns input[name=SelectedTabColumns]');
    var IsChecked = $('#VendorGroupAllColumn').prop("checked");
    $(VendorGroupAllColumn).each(function (index, elem) {
        $(elem).prop('checked', IsChecked)
    });
});
$(document).on('change', '#VendorGroupAllColumn', function () {
    var VendorGroupAllColumn = $('#TabColumns input[name=SelectedTabColumns]');
    var IsChecked = $('#VendorGroupAllColumn').prop("checked");
    $(VendorGroupAllColumn).each(function (index, elem) {
        $(elem).prop('checked', IsChecked)
    });
});
$(document).on('change', '.VendorGroupChechBoxChange', function () {
    var CheckBoxStates = $('#TabColumns input[name=SelectedTabColumns]');
    var IsChecked = true;
    $(CheckBoxStates).each(function (index, elem) {
        if (!$(elem).prop('checked')) {
            IsChecked = false;
            return
        }
    });
    $('#VendorGroupAllColumn').prop('checked', IsChecked);
});
// text element complete text 
$(document).on('input', '.QuotaTxtComplete', function () {
    if (ReportTimerId == null) {
        ReportAutoComElem = $(this).attr('id');
        ReportAutoComElemVal = $("#" + ReportAutoComElem).val();
        ReportTimerId = setInterval(function () {

            var keyword = $("#" + ReportAutoComElem).val();
            if (keyword == ReportAutoComElemVal) {
                var PropName = "";
                if (ReportAutoComElem.indexOf("ReportSelectedVendorName") != -1) {
                    PropName = "ReportSelectedVendorName";
                    $("#SelectedVendorID").val(null);
                }
                if (ReportAutoComElem.indexOf("ReportSelectedGuideName") != -1) {
                    PropName = "ReportSelectedGuideName";
                    $("#SelectedGuideID").val(null);
                }
                if (ReportAutoComElem.indexOf("ReportSelectedCustomerOrgName") != -1) {
                    PropName = "ReportSelectedCustomerOrgName";
                    $("#SelectedCustomerID").val(null);
                }
                var TabName = $("#SelectedTab").length > 0 ? $("#SelectedTab").val() : null;
                var position = $("#" + ReportAutoComElem).offset();
                position.top = position.top + $("#" + ReportAutoComElem).height() + 5;
                $.ajax({
                    url: urls["ReportAutoComplete"],
                    data: { 'PropName': PropName, 'keyword': keyword, TabName: TabName },
                    type: 'POST',
                    success: function (data) {
                        $("#AutoCompleteDiv").html(data);
                        var width = $("#" + ReportAutoComElem).css("width");
                        $("#AutoCompleteDiv").css("width", width);
                        $("#AutoCompleteDiv").show();
                        $("#AutoCompleteDiv").offset(position);
                    },
                    error: function (xhr) {
                        jAlert(xhr.statusText, "Error");
                    },
                    complete: function () {
                        clearInterval(ReportTimerId);
                        ReportTimerId = null;
                    }
                });
            }
            else
                ReportAutoComElemVal = keyword;
        }, 600);
    }
});
$(document).on('click', '.QuotaAutoCompleteDivClose', function () {
    $(this).parent().parent().hide();
});
function htmlDecode(value) {
    return $('<div/>').html(value).text();
}
function AutoCompleteRowClick(key, val) {
    val = htmlDecode(val);
    $("#" + ReportAutoComElem).val(val);
    if (ReportAutoComElem.indexOf("ReportSelectedVendorName") != -1)
        $("#SelectedVendorID").val(key);
    if (ReportAutoComElem.indexOf("ReportSelectedGuideName") != -1)
        $("#SelectedGuideID").val(key);
    if (ReportAutoComElem.indexOf("ReportSelectedCustomerOrgName") != -1)
        $("#SelectedCustomerID").val(key);
    $("#AutoCompleteDiv").hide();
}
$(document).on('change', '#SelectedTab', function () {
    $("#ReportSelectedVendorName").val("");
    $("#SelectedVendorID").val(null);
    $(".QuotaAutoCompleteDivClose").click();
    $('#VendorGroupAllColumn').prop('checked', false);
    var TabName = $("#SelectedTab").length > 0 ? $("#SelectedTab").val() : null;
    if (TabName == "Hotel") {
        $("#CitySearchDiv").hide();
        $("#CategorySearchDiv").hide();
        $("#PlaneSearchDiv").hide();
        $("#CityDropSearchDiv").show();
    }
    if (TabName == "Bus") {
        $("#CityDropSearchDiv").hide();
        $("#CategorySearchDiv").hide();
        $("#PlaneSearchDiv").hide();
        $("#CitySearchDiv").show();
    }
    if (TabName == "Restaurants") {
        $("#CitySearchDiv").hide();
        $("#CityDropSearchDiv").hide();
        $("#PlaneSearchDiv").hide();
        $("#CategorySearchDiv").show();
    }
    if (TabName == "Misc") {
        $("#CityDropSearchDiv").hide();
        $("#CitySearchDiv").hide();
        $("#CategorySearchDiv").hide();
        $("#PlaneSearchDiv").show();
    }
    if (TabName == "Attractions" || TabName == "Guide" || TabName == "Group CheckList") {
        $("#CitySearchDiv").hide();
        $("#CategorySearchDiv").hide();
        $("#PlaneSearchDiv").hide();
        $("#CityDropSearchDiv").hide();
    }

    $.ajax({
        url: urls["ReportLoadColumnsByTabName"],
        data: { TabName: TabName },
        cache: false,
        type: "POST",
        success: function (data) {
            var markup = "";
            var index = 0
            for (var key in data) {
                markup += "<input class=\"VendorGroupChechBoxChange\" id=\"SelectedTabColumns" + index.toString() + "\"" + " name=\"SelectedTabColumns\" type=\"checkbox\" value=\"" + key + "\"" + ">"
                         + "<label class=\"VendorGroupChechBoxChange\" for=\"SelectedTabColumns" + index.toString() + "\"" + ">" + data[key].ColumnName + "</label>"
                         + "<br>"
                //    //markup += "<option value=" + data[x].Value + ">" + data[x].Text + "</option>";
                index++;
            }
            $("#TabColumns").empty();
            $("#TabColumns").html(markup);
        },
        error: function (reponse) {
            jAlert(reponse, "Error");
        },
        complete: function () {
        }
    });
});

